from typing import *


class Solution:

    def numSmallerByFrequency(self, queries: List[str],
                              words: List[str]) -> List[int]:

        def f(word: str):
            return sorted(Counter(word).items())[0][1]

        h = [0] * 11
        for word in words:
            h[f(word)] += 1
        s = [0] * 11
        for i in range(9, -1, -1):
            s[i] = s[i + 1] + h[i + 1]
        ans = []
        for q in queries:
            ans.append(s[f(q)])
        return ans


def f(word: str):
    return sorted(Counter(word).items())[0][1]


print(f('abbcc'))